package com.lagou.rpc.consumer.controller;

import com.lagou.rpc.api.IProductcodeService;
import com.lagou.rpc.api.IUserService;
import com.lagou.rpc.consumer.proxy.RpcClientProxy;
import com.lagou.rpc.pojo.Product;
import com.lagou.rpc.pojo.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {

    @GetMapping("/user/{id}")
    public User user(@PathVariable("id") Integer id){
        IUserService proxy = (IUserService) RpcClientProxy.createProxy(IUserService.class);
        User user = proxy.getById(id);
        System.out.println(user);
        return user;
    }

    @GetMapping("/pro/{id}")
    public Product pro(@PathVariable("id") Integer id){
        IProductcodeService proxy = (IProductcodeService) RpcClientProxy.createProxy(IProductcodeService.class);
        Product product = proxy.getProductById(id);
        System.out.println(product);
        return product;
    }
}
